%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FP011;
/*%LET CLUSTER = 01A;*/

/* IDENTIFYING HANDLE */
%LET COM = &ELI; /*._&CLUSTER.;*/

%LET RHS= 
    A1 A3 B99SP C99SP D2 D3 D99SP E2 E99SP F2 F3 F99SP G2 G3 G4 G99SP
    H1 H2 H3 H4 H5 H6 H7 H8 H9 H10
    BRAND1 BRAND2 BRAND3 BRAND4 BRAND5
    BCOLUM BARAB
    MNAMT MNAMTSQ
    ;

%LET STYR = 0201;
%LET FIRSTPER = 20&STYR.;
%LET LASTPER = 200709;
%LET STDUM = D&STYR.;
%LET RHYRS = D0202 -- D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;
    IF .075 LE PRICE LE 1.775;
    IF 1 LE LNAMT LE 4.4;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    IF INDEX(C99,'COLOM') OR INDEX(C99,'COLUM') THEN BCOLUM=1; ELSE BCOLUM=0;
    IF INDEX(C99,'ARAB') OR SUBSTR(C99,1,4)="ARIB" THEN BARAB=1; ELSE BARAB=0;
    IF C="" THEN BCOLUM=.; IF C="" THEN BARAB=.;
    IF H99="**********" THEN H7=1;
    IF H99="**********" THEN H8=1;
    IF H99="**********" THEN H2=1;
    IF H99="**********" THEN H1=1;
    IF H99="**********" THEN H10=1;
    IF SUBSTR(H99,1,9)="**********" THEN BRAND1=1; ELSE BRAND1=0;
    IF SUBSTR(H99,1,7)="**********" THEN BRAND2=1; ELSE BRAND2=0;
    IF SUBSTR(H99,1,6)="**********" THEN BRAND3=1; ELSE BRAND3=0;
    IF SUBSTR(H99,1,9)="**********" THEN BRAND4=1; ELSE BRAND4=0;
    IF SUBSTR(H99,1,7)="**********" THEN BRAND5=1; ELSE BRAND5=0;
    ARRAY BRARRAY (5) BRAND1-BRAND5;
    DO COUNT=1 TO 5;
        IF H="" THEN BRARRAY(COUNT)=.;
    END;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";